package OrdersSystem;

import static org.junit.Assert.*;

import org.junit.Test;

import DBSystem.DataBase;

public class UserAlertTest {

	DataBase db = new DataBase();
	
	@Test
	
	public void testForwardUserAlert() {
		
		ContactDetails contact = new ContactDetails("Marchmont", "1F1", "Edinburgh", "EH9 1BM",
				"0798993454", "customer1@sms.ed.ac.uk");
		Customer customer = new Customer(111, "Eddie", "Murphy", contact, 0);
		db.storeUser(customer);
		UserAlert testAlertInDB = new UserAlert(1,"This message should be delivered normaly", 111);
		db.storeUserAlert(testAlertInDB);
		//  Test Case #8  Existing Alert, existing user in the Database
		System.out.println("Test Case #8: Existing Alert, existing user in the Database. Alert should be sent successfully");
		UserAlert alertReceivedFromDeliveries = new UserAlert(1);
		String testResult = alertReceivedFromDeliveries.forwardUserAlert();
		System.out.println("TEST RESULT: " + testResult);
		System.out.println();
		assertEquals("Result", true, testResult.contains("The alert has the"));
		
		// Test Case #9 Existing Alert, non existing user in the database() 
		System.out.println("Test Case #9: Existing Alert, non existing user in the Database. Alert should not be sent successfully");
		testAlertInDB = new UserAlert(2, "The receiver of this user does not exist", 130);
		db.storeUserAlert(testAlertInDB);
		alertReceivedFromDeliveries = new UserAlert(2);
		testResult = alertReceivedFromDeliveries.forwardUserAlert();
		System.out.println("TEST RESULT: " + testResult);
		System.out.println();
		assertEquals("Result", true, testResult.contains("no user registered"));
		
		//Test Case #10 non existing alert in the database
		System.out.println("Test Case #10: Non existing Alert in the Database. Alert should not be sent successfully");
		alertReceivedFromDeliveries = new UserAlert(3);
		testResult = alertReceivedFromDeliveries.forwardUserAlert();
		System.out.println("TEST RESULT: " + testResult);
		System.out.println();
		assertEquals("Result", true, testResult.contains("no alert"));
	}

}
